﻿using Pb;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class NNGame : Game
{

    EginUser user = EginUser.Instance;
    EginDN dn = EginDN.Instance;
    //玩家
    public List<NNUser> Users;

    //房间号
    public List<UISprite> roomIDSprits;
    public GameObject roomObj;
    //root
    public GameObject Root;
    //牌的控制
    private NNCardsControl nnCardsControl;

    //抢庄选择倍数预设
    private GameObject BankerMultiple;
    private GameObject PlayerMultiple;
    //音效
    public List<AudioClip> musicMen;
    public List<AudioClip> musicWomen;

    //音效
    public List<AudioClip> textMen;
    public List<AudioClip> textWomen;
    //按钮
    public GameObject SetButton;
    public GameObject ChatButton;
    public GameObject ExitButton;
    public GameObject BankButton;
    //银行
    private GameObject bankPanel;
    private BankModel bankModel;
    public UILabel coinCount;
    public int isHaveCoin = 0;  //已取出的钱数

    #region  牛牛收到的服务器消息
    //斗地主牌型
    private int pokerType { get; set; }

    private int maxPlayerMultiple;
    #endregion



    public string[] dnText = {
        "大家好，很高兴见到各位！",
        "玩就玩大的，抢庄4倍都行！",
        "手里有牛牛金币不用愁",
        "我就呵呵了",
        "有牛了，看我大杀四方",
        "发牌就抢庄，赢牌心不慌",
        "不要走决战到天亮"
    };

    void Awake()
    {
        base.StartGameSocket();
        SocketManager.Instance.socketListener = this;
        UIEventListener.Get(SetButton).onClick = ButtonClick;
        UIEventListener.Get(ChatButton).onClick = ButtonClick;
        UIEventListener.Get(ExitButton).onClick = ButtonClick;
        UIEventListener.Get(BankButton).onClick = ButtonClick;
    }
       
    void ButtonClick(GameObject button)
    {
        if (button.name == "SetButton")
        {
            GameObject Set = NGUITools.AddChild(Root, (GameObject)(Resources.Load(GameDNPrafabPath.Set)));
        }
        else if (button.name == "ChatButton")
        {
            // DNChat
            GameObject DNChat = NGUITools.AddChild(Root, (GameObject)(Resources.Load(GameDNPrafabPath.DNChat)));
        }
        else if (button.name == "ExitButton")
        {
            GameObject Exit = NGUITools.AddChild(Root, (GameObject)(Resources.Load(GameDNPrafabPath.Exit)));
        }
        else if (button.name == "BankBTN")
        {
            Debug.LogError("-------");
            //银行
            bankPanel = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)Resources.Load(HallPrafabPath.Bank));
            bankModel = bankPanel.GetComponent<BankModel>();
            bankModel.sumLabel.text = "已存入:" + user.bankCoinCount + "W金币";
        }
    }
    void Start()
    {
        //加载玩家
        LoadUser();
        //房间号显示
        if (user.ControlScene == 1)
        {
            string tempRoomID = dn.roomId.ToString();
            for (int i = 0; i < 6; i++)
            {
                string str = tempRoomID.Substring(0, 1);
                tempRoomID = tempRoomID.Remove(0, 1);
                roomIDSprits[i].spriteName = str;
            }
        }
        else
        {
            roomObj.SetActive(false);
        }
        if (dn.isReconnect == true)
        {
            dn.isReconnect = false;
            NNReconnect();
        }
        //StartCoroutine(AdvanceLoad()) ;
    }

    /// <summary>
    /// 监听服务器消息
    /// </summary>
    /// <param name="data"></param>
    public override void SocketReceiveMessage(byte[] data)
    {
        base.SocketReceiveMessage(data);
        byte[] dataLength = data.Skip(0).Take(2).ToArray();
        byte[] dataId = data.Skip(2).Take(4).ToArray();
        byte[] dataConcent = data.Skip(data.Length - (data.Length - 4)).ToArray();
        int TempMsgID = ProtoDataToMsg.Byte2ushort(dataId);
        #region 牛牛玩家加入离开房间返回
        if (TempMsgID == MsgId.RoomUserInfoBroadcast)
        {
            Pb.RoomUserInfoBroadcast newpb = Pb.RoomUserInfoBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
           
            if (newpb.UserInfo.SeatStatus == SEAT_STATUS.Sit)
            {
                bool canLoad = true;
                for (int i = 0; i < user.gameUserInfoList.Count; i++)
                {
                    if (user.gameUserInfoList[i].SeatId == newpb.UserInfo.SeatId)
                    {
                    
                        canLoad = false;
                        user.tempGameUserInfoList.Add(newpb.UserInfo);

                    }

                }
                if (canLoad)
                {
                    //加入房间
                    user.gameUserInfoList.Add(newpb.UserInfo);
                    int tempIndex = dn.returnOtherSeatIndex(newpb.UserInfo.SeatId);
                    Users[tempIndex].SeatID = newpb.UserInfo.SeatId;
                    Users[tempIndex].avatarSprit.gameObject.SetActive(true);
                    if (newpb.UserInfo.AvatarUrl != "")
                    {
                        WXAvatarManager._instance.GetWxAvatar(newpb.UserInfo.Uid, Users[tempIndex].wxAvatar, newpb.UserInfo.AvatarUrl);
                        Users[tempIndex].wxAvatar.gameObject.SetActive(true);
                    }
                    else
                    {

                        Users[tempIndex].avatarSprit.spriteName = newpb.UserInfo.AvatarId.ToString();
                        Users[tempIndex].avatarSprit.gameObject.GetComponent<UIButton>().normalSprite = newpb.UserInfo.AvatarId.ToString();
                    }
                    Users[tempIndex].WaitLabel.gameObject.SetActive(false);
                    Users[tempIndex].UserNameLabel.gameObject.SetActive(true);
                    Users[tempIndex].UserNameLabel.text = newpb.UserInfo.Nickname;
                    Users[tempIndex].GoldLabel.gameObject.SetActive(true);
                    //StartCoroutine(GetWWWFACE(Users[tempIndex].wxAvatar, newpb.UserInfo.AvatarUrl));
                    if (user.ControlScene == 1)
                    {
                        string str = user.ReturnRelCoin(newpb.UserInfo.Score);
                        Users[tempIndex].GoldLabel.text = str;
                    }
                    else
                    {
                        string str = user.ReturnRelCoin(newpb.UserInfo.BagCoinCount);
                        Users[tempIndex].GoldLabel.text = str;
                    }
                }


            }
            else if (newpb.UserInfo.SeatStatus == SEAT_STATUS.Leave)
            {
                if (dn.roomStatus != ROOM_STATUS.Gaming)
                {
                    //离开房间
                    for (int i = 0; i < user.gameUserInfoList.Count; i++)
                    {
                        if (newpb.UserInfo.SeatId == user.gameUserInfoList[i].SeatId)
                        {
                            user.gameUserInfoList.RemoveAt(i);
                            int tempIndex = dn.returnOtherSeatIndex(newpb.UserInfo.SeatId);
                            Users[tempIndex].avatarSprit.gameObject.SetActive(false);
                            Users[tempIndex].wxAvatar.gameObject.SetActive(false);
                            Users[tempIndex].WaitLabel.gameObject.SetActive(true);
                            Users[tempIndex].UserNameLabel.gameObject.SetActive(false);
                            Users[tempIndex].GoldLabel.gameObject.SetActive(false);
                            break;
                        }
                    }
                }
            }
        }
        #endregion

        #region 牛牛Game消息
        //发牌
        else if (TempMsgID == MsgId.NnRoomBeginNotification)
        {
            Pb.NnRoomBeginNotification newpb = Pb.NnRoomBeginNotification.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            dn.currentRound = newpb.CurrentRound;
            dn.roomStatus = ROOM_STATUS.Gaming;
            StartCoroutine(OneGameStart(newpb));

        }
        //抢庄消息
        else if (TempMsgID == MsgId.NnBankerMultipleResponse)
        {
            Pb.NnBankerMultipleResponse newpb = Pb.NnBankerMultipleResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
        }
        //抢庄广播
        else if (TempMsgID == MsgId.NnBankerMultipleBroadcast)
        {
            Pb.NnBankerMultipleBroadcast newpb = Pb.NnBankerMultipleBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            int tempSeatID = newpb.SeatId;

            int bankerMultiple = newpb.BankerMultiple;
            //播放抢庄音效
            if (bankerMultiple > 0)
            {
                SoundModel.PlaySound(musicMen[14]);
            }
            int tempIndex = dn.returnOtherSeatIndex(tempSeatID);
            Users[tempIndex].BankerMultipleSet(bankerMultiple);

            //销毁抢庄btn暂时放着
            if (tempSeatID == dn.seatId)
            {
                Destroy(BankerMultiple);
            }

        }
        //庄家广播 谁是庄家 生成倍数预设
        else if (TempMsgID == MsgId.NnBankerResultBroadcast)
        {
            Pb.NnBankerResultBroadcast newpb = Pb.NnBankerResultBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            dn.bankerSid = newpb.SeatId;
            int bankerSeatID = newpb.SeatId;
            List<int> robSid = newpb.RobSidList.ToList();
            //加载抢庄动画
            if (robSid.Count > 0)
            {
                StartCoroutine(QiangBanker(robSid, bankerSeatID));
            }
            else
            {
                LoadPlayerMultiple(bankerSeatID);
            }



        }
        //开牌广播
        else if (TempMsgID == MsgId.NnCardReadyBroadcast)
        {
            Pb.NnCardReadyBroadcast newpb = Pb.NnCardReadyBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            nnCardsControl.ShowPlayerLastCard();
            if (dn.seatId == dn.bankerSid)
            {
                Destroy(PlayerMultiple);
            }


        }
        //闲家设置倍数通知
        else if (TempMsgID == MsgId.NnPlayerMultipleResponse)
        {
            Pb.NnPlayerMultipleResponse newpb = Pb.NnPlayerMultipleResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
        }
        //闲家倍数广播
        else if (TempMsgID == MsgId.NnPlayerMultipleBroadcast)
        {
            Pb.NnPlayerMultipleBroadcast newpb = Pb.NnPlayerMultipleBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            int tempSeatID = newpb.SeatId;
            int tempPlayerMultiple = newpb.PlayerMultiple;
            int tempIndex = dn.returnOtherSeatIndex(tempSeatID);
            Users[tempIndex].PlayMultipleSet(tempPlayerMultiple);
            if (tempSeatID == dn.seatId)
            {
                Destroy(PlayerMultiple);
                //玩家加载牌型
            }
        }
        //玩家开牌通知
        else if (TempMsgID == MsgId.NnPlayResponse)
        {
            Pb.NnPlayResponse newpb = Pb.NnPlayResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);

        }
        //玩家开牌通知
        else if (TempMsgID == MsgId.NnPlayBroadcast)
        {
            Pb.NnPlayBroadcast newpb = Pb.NnPlayBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            int tempSeatID = newpb.SeatId;
            int PokerType = newpb.PokerType;
            List<int> cardList = newpb.CardList.ToList();
            nnCardsControl.ShowCard(cardList, PokerType, tempSeatID);
            //播放牛几
            if (dn.seatId == tempSeatID)
            {
                if (user.sex == SEX.Male)
                {
                    SoundModel.PlaySound(musicMen[PokerType]);
                }
                else
                {
                    SoundModel.PlaySound(musicWomen[PokerType]);
                }

            }
        }
        //游戏结算
        else if (TempMsgID == MsgId.NnGameOverBroadcast)
        {
            Pb.NnGameOverBroadcast newpb = Pb.NnGameOverBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            dn.roomStatus = ROOM_STATUS.GameOver;
            List<GameOverUserInfo> gameOverUserInfo = newpb.UserList.ToList();
            GameObject GameOver = NGUITools.AddChild(Root, (GameObject)(Resources.Load(GameDNPrafabPath.GameOver)));
            NNGameOver nnGameOver = GameOver.GetComponent<NNGameOver>();
            nnGameOver.gameOverUserInfo = gameOverUserInfo;

            //播放牛牛对局结束失败胜利音效
            int OwnScore = 0;
            for (int i = 0; i < gameOverUserInfo.Count; i++)
            {
                if (dn.seatId == gameOverUserInfo[i].SeatId)
                {
                    OwnScore = gameOverUserInfo[i].RoundScore;
                    break;
                }
            }
            if (OwnScore > 0)
            {
                SoundModel.PlaySound(musicMen[15]);
            }
            else
            {
                SoundModel.PlaySound(musicMen[16]);
            }


            nnGameOver.IsOver = newpb.IsGameOver;
            if (user.ControlScene == 1)
            {
                for (int i = 0; i < gameOverUserInfo.Count; i++)
                {
                    for (int j = 0; j < user.gameUserInfoList.Count; j++)
                    {
                        if (gameOverUserInfo[i].SeatId == user.gameUserInfoList[j].SeatId)
                        {
                            int tempIndex = dn.returnOtherSeatIndex(gameOverUserInfo[i].SeatId);
                            user.gameUserInfoList[j].Score += gameOverUserInfo[i].RoundScore;
                            string str = user.ReturnRelCoin(user.gameUserInfoList[j].Score);
                            Users[tempIndex].GoldLabel.text = str;
                        }
                    }

                }
            }
            else
            {
                for (int i = 0; i < gameOverUserInfo.Count; i++)
                {
                    if (dn.seatId == gameOverUserInfo[i].SeatId)
                    {
                        user.coinCount = gameOverUserInfo[i].BagCoinCount.ToString();
                    }

                    for (int j = 0; j < user.gameUserInfoList.Count; j++)
                    {
                        if (gameOverUserInfo[i].SeatId == user.gameUserInfoList[j].SeatId)
                        {
                            int tempIndex = dn.returnOtherSeatIndex(gameOverUserInfo[i].SeatId);
                            user.gameUserInfoList[j].BagCoinCount += gameOverUserInfo[i].RoundScore;
                            string str = user.ReturnRelCoin(user.gameUserInfoList[j].BagCoinCount);
                            Users[tempIndex].GoldLabel.text = str;
                        }

                    }
                }
            }

        }

        #endregion
        //离开房间
        else if (TempMsgID == MsgId.RoomLeaveResponse)
        {
            Pb.RoomLeaveResponse newpb = Pb.RoomLeaveResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            Debug.LogError(newpb.Msg);
            if (newpb.Status == STATUS.Success)
            {
                EginUser.Instance.gameUserInfoList.Clear();
                Application.LoadLevel(ScenePath.Hall);

            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(Root, (GameObject)(Resources.Load("LogMsg")));
            }
        }
        else if (TempMsgID == MsgId.RoomDismissBroadcast)
        {
            Pb.RoomDismissBroadcast newpb = Pb.RoomDismissBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            EginUser.Instance.gameUserInfoList.Clear();
            Application.LoadLevel(ScenePath.Hall);
        }
        //开始倒计时
        else if (TempMsgID == MsgId.NnGameCountdownBroadcast)
        {
            Pb.NnGameCountdownBroadcast newpb = Pb.NnGameCountdownBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            GameObject StartHint = NGUITools.AddChild(Root, (GameObject)(Resources.Load(GameDNPrafabPath.StartHint)));
        }

        #region 文字表情聊天
        else if (TempMsgID == MsgId.RoomChatBroadcast)
        {
            Pb.RoomChatBroadcast newpb = Pb.RoomChatBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            StartCoroutine(TextFaceChat(newpb));
        }
        #endregion
        //网络异常
        else if (TempMsgID == MsgId.NetWorkAbnormalMessage)
        {
            GameObject NetWorkAbnormal = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("NetWorkAbnormal")));
        }
        #region 银行
        //存钱（服务器返回）
        else if (TempMsgID == MsgId.Bag2BankResponse)
        {
            Bag2BankResponse newpb = Bag2BankResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                //if (BankPanel && bankModel)
                {
                    print("进入了" + newpb.BankCointCount);
                    user.bankCoinCount += bankModel.StrToInt(bankModel.getInLabel.text);
                    bankModel.sumLabel.text = "已存入：" + user.bankCoinCount + "万金币";
                    bankModel.getInLabel.text = "0万";
                }
                //设置背包里的钱数
                coinCount.text = user.ReturnMoney(newpb.BagCointCount);
                user.logMsg = "存入成功";
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }
        //取钱（服务器返回）
        else if (TempMsgID == MsgId.Bank2BagResponse)
        {
            Bank2BagResponse newpb = Bank2BagResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                //if (bankPanel && bankModel)
                {
                    user.bankCoinCount -= bankModel.StrToInt(bankModel.getOutLabel.text);
                    isHaveCoin = bankModel.StrToInt(bankModel.getOutLabel.text);
                    bankModel.sumLabel.text = "已取出：" + isHaveCoin + "万金币";
                    bankModel.getOutLabel.text = "0万";
                }
                //设置背包里的钱数
                coinCount.text = user.ReturnMoney(newpb.BagCointCount);
                user.logMsg = "取出成功";
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }
        #endregion
    }
    /// <summary>
    /// 加载玩家状态 +添加第三人进入房间旁观
    /// </summary>
    void LoadUser()
    {
        dn.SortSeatId();
        bool tempIsWitness = false;
        for (int i = 0; i < user.gameUserInfoList.Count; i++)
        {
            int tempIndex = dn.returnOtherSeatIndex(user.gameUserInfoList[i].SeatId);
            Users[tempIndex].SeatID = user.gameUserInfoList[i].SeatId;
            Users[tempIndex].avatarSprit.gameObject.SetActive(true);
            if (user.gameUserInfoList[i].AvatarUrl != "")
            {
                WXAvatarManager._instance.GetWxAvatar(user.gameUserInfoList[i].Uid, Users[tempIndex].wxAvatar, user.gameUserInfoList[i].AvatarUrl);
                Users[tempIndex].wxAvatar.gameObject.SetActive(true);
            }
            else
            {
                Users[tempIndex].avatarSprit.spriteName = user.gameUserInfoList[i].AvatarId.ToString();
                Users[tempIndex].avatarSprit.gameObject.GetComponent<UIButton>().normalSprite = user.gameUserInfoList[i].AvatarId.ToString();
            }
            Users[tempIndex].WaitLabel.gameObject.SetActive(false);
            Users[tempIndex].UserNameLabel.gameObject.SetActive(true);
            Users[tempIndex].UserNameLabel.text = user.gameUserInfoList[i].Nickname;
            Users[tempIndex].GoldLabel.gameObject.SetActive(true);
            //StartCoroutine(GetWWWFACE(Users[tempIndex].wxAvatar, user.gameUserInfoList[i].AvatarUrl));
            if (user.ControlScene == 1)
            {
                string str = user.ReturnRelCoin(user.gameUserInfoList[i].Score);
                Users[tempIndex].GoldLabel.text = str;
            }
            else
            {
                string str = user.ReturnRelCoin(user.gameUserInfoList[i].BagCoinCount);
                Users[tempIndex].GoldLabel.text = str;
            }
            Debug.Log(user.gameUserInfoList[i].IsWitness);
            //判断是否有旁观者
            if (user.gameUserInfoList[i].IsWitness)
            {
                tempIsWitness = true;
            }
        }
        if (tempIsWitness && dn.roomStatus == ROOM_STATUS.Gaming)
        {
            Debug.Log("旁观加载牌");
            GameObject NNCards = NGUITools.AddChild(Root, (GameObject)(Resources.Load(GameDNPrafabPath.Cards)));
            nnCardsControl = NNCards.GetComponent<NNCardsControl>();
            nnCardsControl.OtherJoinShowCard();
            for (int i = 0; i < user.gameUserInfoList.Count; i++)
            {
                if (user.gameUserInfoList[i].OutCardList.Count > 0)
                {
                    nnCardsControl.ShowCard(user.gameUserInfoList[i].OutCardList.ToList(), user.gameUserInfoList[i].PokerType, user.gameUserInfoList[i].SeatId);
                }
            }
        }
    }
    //public UILabel test;
    //private float TimeOne;
    //private float TimeTwo;
    /// <summary>
    /// 发牌+开始动画
    /// </summary>
    /// <param name="newpb"></param>
    /// <returns></returns>
    IEnumerator OneGameStart(NnRoomBeginNotification newpb)
    {

        //TimeOne = Time.realtimeSinceStartup;
        GameObject StartAnimation = NGUITools.AddChild(Root, (GameObject)(Resources.Load(GameDNPrafabPath.StartAnimation)));
        //TimeTwo = Time.realtimeSinceStartup;
        //float time = TimeTwo - TimeOne;
        //test.text = "加载ani的时间为" + time;
        yield return new WaitForSeconds(1.5f);
        Destroy(StartAnimation);
        //玩家的牌处理
        GameObject NNCards = NGUITools.AddChild(Root, (GameObject)(Resources.Load(GameDNPrafabPath.Cards)));
        nnCardsControl = NNCards.GetComponent<NNCardsControl>();
        nnCardsControl.ownCards = newpb.CardList.ToList();
        nnCardsControl.ShowOwnCards(newpb.CardList.ToList(), newpb.SeatId, newpb.PokerType);
        maxPlayerMultiple = newpb.MaxPlayerMultiple;
        //牛几存储
        pokerType = newpb.PokerType;
        //最大抢庄倍数 玩家下庄倍数处理
        BankerMultiple = NGUITools.AddChild(Root, (GameObject)(Resources.Load(GameDNPrafabPath.BankerMultiple)));
        NNBankerMultiple nnBankerMultiple = BankerMultiple.GetComponent<NNBankerMultiple>();
        nnBankerMultiple.ShowCanClick(newpb.MaxBankerMultiple);

    }
    /// <summary>
    /// 抢庄
    /// </summary>
    /// <param name="robSid"></param>
    /// <param name="bankSid"></param>
    /// <returns></returns>
    IEnumerator QiangBanker(List<int> robSid, int bankSid)
    {
        int tempInt = 0;
        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j < robSid.Count; j++)
            {
                Users[tempInt].BankerStatus.SetActive(false);
                int tempIndex = dn.returnOtherSeatIndex(robSid[j]);
                tempInt = tempIndex;
                Users[tempIndex].BankerStatus.SetActive(true);
                yield return new WaitForSeconds(0.05f);
            }
        }
        Users[tempInt].BankerStatus.SetActive(false);
        LoadPlayerMultiple(bankSid);
    }
    /// <summary>
    /// 文字表情聊天   
    /// </summary>
    /// <param name="newpb"></param>
    /// <returns></returns>
    IEnumerator TextFaceChat(RoomChatBroadcast newpb)
    {
        int tempIndex = 0;
        for (int i = 0; i < user.gameUserInfoList.Count; i++)
        {
            if (newpb.FromUid == user.gameUserInfoList[i].Uid)
            {
                int tempSeatid = user.gameUserInfoList[i].SeatId;
                tempIndex = dn.returnOtherSeatIndex(tempSeatid);
                if (newpb.MsgType == RoomChatType.TextId)
                {
                    Users[tempIndex].textObj.SetActive(true);
                    Users[tempIndex].text.text = dnText[int.Parse(newpb.Content) - 1];
                    if (user.gameUserInfoList[i].Sex == SEX.Male)
                    {
                        SoundModel.PlaySound(textMen[int.Parse(newpb.Content) - 1]);
                    }
                    else
                    {
                        SoundModel.PlaySound(textWomen[int.Parse(newpb.Content) - 1]);
                    }
                }
                else if (newpb.MsgType == RoomChatType.MovieClip)
                {
                    Users[tempIndex].face.gameObject.SetActive(true);
                    Users[tempIndex].face.spriteName = "emotion_0" + newpb.Content;
                }

            }
        }
        yield return new WaitForSeconds(2.5f);
        Users[tempIndex].textObj.SetActive(false);
        Users[tempIndex].face.gameObject.SetActive(false);
    }

    /// <summary>
    /// 初始化玩家状态
    /// </summary>
    public void UserInit()
    {
        for (int i = 0; i < Users.Count; i++)
        {
            Users[i].Init();
        }
    }

    /// <summary>
    /// 加载倍数选择预设
    /// </summary>
    void LoadPlayerMultiple(int bankSid)
    {
        int tempSid = dn.returnOtherSeatIndex(bankSid);
        Users[tempSid].BankerStatus.SetActive(true);
        Users[tempSid].Banker.SetActive(true);
        if (Users[tempSid].NoQiang.activeSelf)
        {
            Users[tempSid].NoQiang.SetActive(false);
            Users[tempSid].Qiang.SetActive(true);
            Users[tempSid].MultipleSprit.spriteName = "1";
        }
        for (int i = 0; i < user.gameUserInfoList.Count; i++)
        {
            if (dn.seatId == user.gameUserInfoList[i].SeatId)
            {
                if (user.gameUserInfoList[i].IsWitness)
                {
                    user.gameUserInfoList[i].IsWitness = false;
                }
                else
                {
                    Debug.Log("执行抢庄后加载倍数操作");
                    if (bankSid != dn.seatId)
                    {
                        PlayerMultiple = NGUITools.AddChild(Root, (GameObject)(Resources.Load(GameDNPrafabPath.PlayerMultiple)));
                        NNPlayerMultiple nnPlayerMultiple = PlayerMultiple.GetComponent<NNPlayerMultiple>();
                        nnPlayerMultiple.ShowCanClick(maxPlayerMultiple);
                    }
                    else
                    {
                        PlayerMultiple = NGUITools.AddChild(Root, (GameObject)(Resources.Load(GameDNPrafabPath.BankerTitle)));
                    }
                }
            }
        }


    }

    #region 重连
    /// <summary>
    /// 斗牛重连
    /// </summary>
    void NNReconnect()
    {

        NnReconnectRoomResponse newpb = dn.nnReconnectRoomResponse;
        //加载庄家 以及玩家抢庄 和倍数处理（判断是否有庄家 有的话判断是否是庄家本人 是的加载庄家抢庄倍数 不是判断是否有闲家倍数 有加载闲家倍数无加载闲家抢庄）
        Debug.Log("BankerSid;" + newpb.BankerSid);
        if (newpb.BankerSid != 0)
        {
            int tempSid = dn.returnOtherSeatIndex(newpb.BankerSid);
            Users[tempSid].BankerStatus.SetActive(true);
            Users[tempSid].Banker.SetActive(true);

            for (int i = 0; i < newpb.UserList.Count; i++)
            {
                //显示抢几             
                int tempIndex = dn.returnOtherSeatIndex(newpb.UserList[i].SeatId);
                //Users[tempIndex].BankerMultipleSet(newpb.UserList[i].BankMultiple);
                if (newpb.UserList[i].SeatId == newpb.BankerSid)
                {
                    Users[tempIndex].BankerMultipleSet(newpb.UserList[i].BankMultiple);
                }
                else
                {
                    //判断是否有闲家倍数  有：显示闲家倍数（并加载owncardtype） 无：加载抢庄倍数
                    if (newpb.UserList[i].PlayerMultiple != 0)
                    {
                        Users[tempIndex].PlayMultipleSet(newpb.UserList[i].PlayerMultiple);

                    }
                    else
                    {
                        Users[tempIndex].BankerMultipleSet(newpb.UserList[i].BankMultiple);
                    }
                }

            }

        }
        else
        {
            //不处理
        }
        //加载牌
        if (newpb.CardList.Count > 0)
        {
            GameObject NNCards = NGUITools.AddChild(Root, (GameObject)(Resources.Load(GameDNPrafabPath.Cards)));
            nnCardsControl = NNCards.GetComponent<NNCardsControl>();
            nnCardsControl.ownCards = newpb.CardList.ToList();
            nnCardsControl.ShowOwnCards(newpb.CardList.ToList(), newpb.SeatId, newpb.PokerType);
            maxPlayerMultiple = newpb.MaxPlayerMultiple;
            nnCardsControl.ReconnectShowCard();
        }


        bool isHaveOutCard = false;
        bool isShowLastCard = false;
        for (int i = 0; i < newpb.UserList.Count; i++)
        {
            if (newpb.UserList[i].OutCardList.Count > 0)
            {
                isHaveOutCard = true;
                break;
            }
        }
        for (int i = 0; i < newpb.UserList.Count; i++)
        {
            if (newpb.UserList[i].PlayerMultiple != 0)
            {
                isShowLastCard = true;
                break;
            }
        }

        if (isHaveOutCard)
        {
            //直接显示牛几 并把开牌的玩家的牌显示出来
            for (int i = 0; i < newpb.UserList.Count; i++)
            {
                if (newpb.UserList[i].OutCardList.Count > 0)
                {
                    nnCardsControl.ShowCard(newpb.UserList[i].OutCardList.ToList(), newpb.UserList[i].PokerType, newpb.UserList[i].SeatId);
                }

            }
        }
        else
        {
            if (isShowLastCard)
            {
                //显示什么即将为你开牌 最后一张牌
                for (int i = 0; i < newpb.UserList.Count; i++)
                {
                    if (newpb.UserList[i].SeatId == newpb.SeatId)
                    {
                        if (newpb.UserList[i].PlayerMultiple != 0)
                        {
                            nnCardsControl.ShowPlayerLastCard();
                        }
                        if (newpb.UserList[i].SeatId == newpb.BankerSid)
                        {
                            nnCardsControl.ShowBankerLastCard();
                        }
                    }
                }
            }
            else
            {
                //不显示最后一张牌 判断是否是庄家 是的话显示什么即将为你开牌 最后一张牌
                if (newpb.SeatId == newpb.BankerSid)
                {
                    nnCardsControl.ShowBankerLastCard();
                }
                else
                {

                }
            }
        }
    }
    #endregion 重连

    IEnumerator AdvanceLoad()
    {
        yield return new WaitForSeconds(0.5f);
        Debug.Log("预加载");
        GameObject StartAnimation = NGUITools.AddChild(Root, (GameObject)(Resources.Load(GameDNPrafabPath.StartAnimation)));
        StartAnimation.SetActive(false);
        GameObject GameOver = NGUITools.AddChild(Root, (GameObject)(Resources.Load(GameDNPrafabPath.GameOver)));
        GameOver.SetActive(false);
    }

    //GameObject LoadModelReturnObj(string TempPath)
    //{
    //    UnityEngine.Object Obj = Resources.Load(TempPath, typeof(GameObject));
    //    GameObject go = Instantiate(Obj, Vector3.zero, transform.rotation, this.transform) as GameObject;
    //    return go;
    //}

    /// <summary>
    /// 加载微信头像
    /// </summary>
    /// <param name="url"></param>
    /// <returns></returns>
    //IEnumerator GetWWWFACE(UITexture texture, string url)
    //{

    //    if (url != "")
    //    {
    //        WWW www = new WWW(url);
    //        yield return www;
    //        if (www.isDone)
    //        {
    //            if (www.error == null) { }
    //            texture.mainTexture = www.texture;

    //        }
    //        else
    //        {

    //        }
    //        www.Dispose();
    //    }

    //}

}
